<?php

namespace App\Models\Shop;

use App\Models\BaseModel;
use Carbon\Carbon;

class UpgradeModel extends BaseModel
{
    protected $table = 'upgrade';

    protected $primaryKey = 'id';

    public $dateFormat = 'U';

    public $dates = [
        'created_at',
        'updated_at',
        'cycle_at'
    ];

    public function user()
    {
        return $this->belongsTo('DC\UserCenter\Models\UserBaseModel','user_id','member_id');
    }


//    public function up_info()
//    {
//        return $this->belongsTo('App\Models\Shop\UpgradeInfoModel','id','upgrade_id');
//    }

    public function createUpgrade($upgrade_data)
    {
        $pay_price = abs(get_rule('gw_award1'));
        $now = Carbon::now()->timestamp;
        $model = new  self();
        $model->user_id = $upgrade_data['user_id'];
        $model->hand_uids = $upgrade_data['hand_uids'];
        $model->up_before_level = $upgrade_data['up_before_level'];
        $model->up_after_level = $upgrade_data['up_after_level'];
        $model->pay_money = $pay_price;
        $model->status = 1;
        $model->created_at = $now;
        $model->cycle_at = $now + 7200;
        if($model->save()){
            return $model->id;
        }

        return false;
    }

}
